home *** CD-ROM | disk | FTP | other *** search
/ Alde ADA 1: #1 / CCCC 8804 Volume 1 Number 1 - Alde.iso / C / MISC / FUNC / PROFF.ARC / PUTWRD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-21  |  1.2 KB  |  49 lines

  1. #include <stdio.h>
  2. #include "proff.h"
  3. #include "debug.h"
  4.  
  5. /*
  6.  * putwrd - put a word in outbuf; includes margin justification
  7.  *
  8.  */
  9. putwrd(wrdbuf)
  10. char wrdbuf[];
  11. {
  12.    int last, llval, extra, w;
  13.  
  14.    dprintf("putwrd  ");
  15.    w = width(wrdbuf);
  16.    last = strlen(wrdbuf) + outp;       /* new end of outbuf */
  17. #ifdef DEBUG
  18.    printf("strlen(wrdbuf) = %d\n", strlen(wrdbuf));
  19. #endif
  20.    llval = rmval - tival;
  21.    if (outw + w > llval || last >= MAXOUT)
  22.    {                                   /* too big */
  23.       last -= outp;
  24.       extra = llval - outw;
  25. #ifdef DEBUG
  26.       printf("extra = %d\n", extra);
  27. #endif
  28.       for (; outp > 0; outp--)
  29.          if (outbuf[outp - 1] == ' ')
  30.             extra++;
  31.          else
  32.             break;
  33.       if (rjust == YES)
  34.       {
  35.          spread(outbuf, outp, extra, outwds);
  36.          if (extra > 0 && outwds > 1)
  37.             outp += extra;
  38.       }
  39.       brk();                           /* flush previous line */
  40.    }
  41. #ifdef DEBUG
  42.    printf("putwrd: last=%d w=%d outp=%d llval=%d outw=%d extra=%d\n", last, w, outp, llval, outw, extra);
  43. #endif
  44.    strcpy(&outbuf[outp], wrdbuf);
  45.    outp = last;
  46.    outw += w;
  47.    outwds++;
  48. }
  49.